<?php
$this->Html->addCrumb('Image Gallery', '/image-gallery-admin');
$this->Html->addCrumb('Categories');
$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
         $(".deleteLink").click(function(event){
          var $link = $(this);
          $.TWS_Overlay("confirm", {title : "Delete confirmation", message : "Are you sure you want to delete this category? <br/><br/>Please note all Albums and Photos linked to this category will also be deleted!", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); location.href=$link.attr("href");}}}});
          event.preventDefault();
        });

        $(".displayContent").cluetip({splitTitle: "|", cluetipClass: "tws", dropShadow : false, positionBy : "mouse", cursor : "default"});
      });
       ';
$this->Html->scriptEnd();
?>

<h1>Categories</h1>
<?php echo $this->Session->flash();?>
<?php echo '<div id="actionLink">'.$this->Html->link('Add Category', array('controller' => 'Categories', 'action' => 'add')).'</div>'; ?>
<? if (empty($categories)) { echo '<p>No Categories are currently available.</p>'; }
 else {
  ?>
   <table class="results" >
    <thead>
      <tr>
        <th width="20%"><?php echo $this->Paginator->sort('name','Category')?></th>
        <th width="25%"><?php echo $this->Paginator->sort('description','Description')?></th>
        <th width="10%"><?php echo $this->Paginator->sort('company_id','Photographer')?></th>
        <th width="10%"><?php echo $this->Paginator->sort('modified','Modified')?></th>
        <th width="20%">Category Photo Albums</th>
        <th width="15%">Actions</th>
      <tr>
   </thead>
   <tbody>
      <?php foreach ($categories as $category) {
        $rec = $category['Category'];
        $editLink = $this->Html->link('Edit', array('controller' => 'categories', 'action' => 'edit', $rec['id']), array("title"=>"Edit this record"));
        $deleteLink = $this->Html->link('Delete', array('controller' => 'categories', 'action' => 'delete', $rec['id']), array("title"=>"Delete this record", "class"=>'deleteLink'));
        $albumsLink = $this->Html->link('Edit albums', array('controller' => 'albums', 'action' => 'index', $rec['id']), array("title"=>"Edit albums for this category"));
        $description = $this->Html->displayPreview(($rec['description']));
        $modified = new DateTime($rec['modified']);
        $photographer = !empty($rec['company_id']) ? "Yes" : "";
        echo '<tr>';
        echo '<td>'.$rec['name'].'</td>';
        echo '<td>'.nl2br($description).'</td>';
        echo "<td>$photographer</td>";
        echo '<td>'.$modified->format('m/d/Y').'</td>';
        echo "<td>$albumsLink</td>";
        echo "<td>$editLink&nbsp;&nbsp;$deleteLink</td>";
        echo '</tr>';
      }?>
   </tbody>
   </table>
  
<?php echo $this->element('pagination'); ?>

 <?php } ?>

